package juc.thread.threadPool;

import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/*
* 定时任务
* 每周三 19:00执行任务
* */
public class Test10 {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime time = now.with(DayOfWeek.WEDNESDAY).withHour(19).withMinute(0).withSecond(0).withNano(0);
        if(now.compareTo(time)>0){
            time=time.plusWeeks(1);
        }
        System.out.println(time);
        long initialDelay = Duration.between(now,time ).toMillis();
        long period=1000*60*60*24*7;
        scheduledExecutorService.scheduleAtFixedRate(()->{},initialDelay ,period, TimeUnit.MILLISECONDS);
    }
}
